<?php

namespace Home\Controller;
use Think\Controller;

class ComplaintController extends Controller{

   public function createComplaint(){
       $data = I();
       if (IS_AJAX){
           if (empty($data['orderid'])){
               datamsg(0,'缺少订单号');
           }
           if(empty($data['detail'])){
               datamsg(0,'请输入投诉内容');
           }
           $where['orderid'] = $data['orderid'];
           $data['companyid'] = 'xiaoyichuxing';
           $data['complainttime'] = time()
           ;
           $complaint = M('complaint');
           $ise = $complaint->where($where)->find();
           if ($ise){
               echo '订单已投诉';
           }
           $res = $complaint->add($data);
           if ($res){
               $save['iscomplaint'] = 1;
               M('xllog')->where($where)->save($save);
               datamsg(1,'投诉成功');
           }else{
               datamsg(0,'投诉失败请重试');
           }
       }else{
           $this->assign('orderid',$data['orderid']);
           $this->display('createcomplaint');
       }


   }

}